package com.example.es.controller;

import com.example.es.test.FileUtils;

import java.io.*;
import java.security.SecureRandom;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;

public class TestDemo {
    public static void main(String[] args) {
        System.out.println(1);
    }
    public static void main9(String[] args) {
        List<String> list = Arrays.asList("张三","张三丰","成龙","周星驰");
        list.stream().filter(s -> s.startsWith("张")).filter(s -> s.length() == 2).forEach(s -> System.out.println(s));
        System.out.println("----------");
        list.stream()
                .filter(s->s.startsWith("张"))
                .filter(s->s.length() == 3)
                .forEach(System.out::println);
    }
//    public static void main(String[] args) {
//        String s = "1+2";
//        System.out.println(s.split("\\+").length);
//    }
    public static void main7(String[] args) {
        String s = "test.json";
        String[] split = s.split("\\.");
        for (int i = 0; i < split.length; i++) {
            System.out.println(split[i]);
        }

    }
    public static void main6(String[] args) {
        String s = "savavadvadwebsdv";
        if(s.contains("web")) {
            System.out.println("true");
        } else {
            System.out.println("false");
        }
    }
    public static void main4(String[] args) {
//        SecureRandom random = new SecureRandom();
//        System.out.println(random.nextInt());
        System.out.println(new SecureRandom().nextInt());
    }
    public static void main8(String[] args) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
        LocalDateTime currentDateTime = LocalDateTime.now();
        currentDateTime.format(dateTimeFormatter);
        System.out.println(currentDateTime.format(dateTimeFormatter));
    }
    public static void main1(String[] args) {
        File file = new File("E:\\zkqa\\listenpath\\");
        List<String> list = new ArrayList<>();
        FileUtils.visitAllDirsAndFiles(file,list);
        list.remove(file.getAbsolutePath());
        for (String s:list) {
            System.out.println(s.substring(file.getAbsolutePath().length()+1));
        }

    }
    public static void main10(String[] args) throws InterruptedException {
        File file = new File("E:\\zkqa\\listenpath\\2023-12-19.json");
        File file1 = new File("E:\\zkqa\\listenpath\\2023-12-20.json");
        File file2 = new File("E:\\zkqa\\listenpath\\2023-12-21.json");
        File file3 = new File("E:\\zkqa\\listenpath\\2023-12-22.json");

        for (int i = 0; i < 5; i++) {
//            int randomSleepTime = new Random().nextInt(10000);
//            Thread.sleep(randomSleepTime);
            synchronized (TestDemo.class) {
                String s = "2023-11-13 15:42:31 [24315]:auth_type:[pop],extra_type:[],acct_id:[498483],domain_id:[496704],acct_type:[0],domain_type:[0],acct_name:[yuanren],real_acc_name:[yuanren],domain_name:[sgcc.com.cn],real_domain_name:[sgcc.com.cn],admin_type:[0],client_ip:[122.10.141.107],server_name:[localhost],reault:[Auth Success]";
                String s1 = "2023-11-13 15:42:31 [24315]:auth_type:[pop],extra_type:[],acct_id:[498483],domain_id:[496704],acct_type:[0],domain_type:[0].acct_name:[yuanren],real_acc_name:[yuanren],domain_name:[sgcc.com.cn].real_domain_name:[sgcc.com.cn],admin_type:[0],client_ip:[122.10.141.107],server_name:[localhost],reasult:[Auth Success]\r\n2023-11-13 15:42:31 [24315]:auth_type:[pop],extra_type:[],acct_id:[498483],domain_id:[496704],acct_type:[0],domain_type:[0].acct_name:[yuanren],real_acc_name:[yuanren],domain_name:[sgcc.com.cn].real_domain_name:[sgcc.com.cn],admin_type:[0],client_ip:[122.10.141.107],server_name:[localhost],reasult:[Auth Success]";
//                String s2 = "2023-11-09 20:16:36 [32021]:auth_type:[pop],extra_type:[],acct_id:[498483],domain_id:[496704],acct_type:[0],domain_type:[0],acct_name:[yuanren],real_acc_name:[yuanren],domain_name:[sgcc.com.cn],real_domain_name:[sgcc.com.cn],admin_type:[0],client_ip:[166.176.121.155],server_name:[localhost],reasult:[Auth Success]";
                try {
                    org.apache.commons.io.FileUtils.writeStringToFile(file3, s+"\r\n", "utf-8",true);
                } catch (IOException e) {
                }
                System.out.println(i);
            }
        }
//        Date date = new Date();
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
//        String format = simpleDateFormat.format(date);
//        System.out.println(format);
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH");
        String format1 = format.format(date);
        System.out.println(format1);
        Calendar calendar =Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.HOUR_OF_DAY,-1);
        Date time = calendar.getTime();
        String format2 = format.format(time);
        System.out.println(format2);

    }

    private static String getRandomString(String str1, String str2) {
        Random random = new Random();
        // 生成 0 或 1，作为选择字符串的索引
        int randomIndex = random.nextInt(2);

        // 根据随机生成的索引选择一个字符串
        return (randomIndex == 0) ? str1 : str2;
    }
}
